package wechat

import (
	"github.com/chanxuehong/wechat/mp/message/request"
	"strings"
)

/****************************************
*收到“姓名@*”文本后，保存用户姓名name字段
****************************************/
func RegNameHandler(reqObj interface{}, reqtext string) (string, error) {
	mp_text := reqObj.(*request.Text)
	reg_uername := strings.TrimPrefix(reqtext, "姓名@")
	user := &User{
		UserID: mp_text.FromUserName,
		Name:   reg_uername}
	return user.RegName()
}

/****************************************
*收到“琴岛通@*”前缀的文本后，保存绑定公交卡
****************************************/
func QDTBindHandler(reqObj interface{}, reqtext string) (string, error) {
	mp_text := reqObj.(*request.Text)
	cardNo := strings.TrimPrefix(reqtext, "琴岛通@")
	user := &User{
		UserID:    mp_text.FromUserName,
		TransCard: `QDT://` + cardNo}
	return user.BindTransCard()
}

/****************************************
*收到“公交卡余额”的文本后，保存用户姓名name字段
****************************************/
func TransCardQueryHandler(reqObj interface{}, reqtext string) (string, error) {
	mp_text := reqObj.(*request.Text)
	user := &User{UserID: mp_text.FromUserName}
	return user.QueryTransCard()
}

/****************************************
*收到“@head@”文本后，保存MSGTYPE_REG_HEADPIC_TEXT状态
****************************************/
func RegHeadTextHandler(reqObj interface{}, reqtext string) (string, error) {
	mp_text := reqObj.(*request.Text)
	user := &User{
		UserID:      mp_text.FromUserName,
		Name:        mp_text.FromUserName,
		LastMsgType: MSGTYPE_REG_HEADPIC_TEXT}
	return user.PrepareUploadHeadPic()
}
